<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>多线程编程实战指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            overflow-x: auto;
        }
        .code-block pre {
            margin: 0;
            padding: 1.5rem;
            font-family: 'Consolas', 'Monaco', monospace;
            font-size: 0.875rem;
            line-height: 1.5;
        }
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        .section-number {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 2.5rem;
            height: 2.5rem;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border-radius: 50%;
            font-weight: 700;
            margin-right: 1rem;
        }
        .highlight-text {
            background: linear-gradient(to right, #667eea, #764ba2);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-weight: 600;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 leading-tight">
                    多线程编程实战指南
                </h1>
                <p class="text-xl md:text-2xl mb-8 opacity-90">
                    掌握高并发场景下的多线程技术，提升系统性能与响应速度
                </p>
                <div class="flex justify-center space-x-6 text-lg">
                    <div class="flex items-center">
                        <i class="fas fa-rocket mr-2"></i>
                        <span>高性能</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-shield-alt mr-2"></i>
                        <span>线程安全</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-code mr-2"></i>
                        <span>实战案例</span>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Introduction -->
    <section class="py-16 bg-white">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto">
                <p class="text-lg leading-relaxed text-gray-700">
                    <span class="drop-cap">在</span>实际项目中，多线程场景非常常见，特别是在需要处理高并发任务、提高系统性能和响应速度的情况下。本指南将深入探讨多线程编程的核心场景与最佳实践，帮助您构建高效、稳定的并发系统。
                </p>
            </div>
        </div>
    </section>

    <!-- Visualization -->
    <section class="py-16 bg-gray-50">
        <div class="container mx-auto px-6">
            <div class="max-w-6xl mx-auto">
                <h2 class="text-3xl font-bold text-center mb-12 text-gray-800">多线程应用场景全景图</h2>
                <div class="bg-white rounded-lg shadow-lg p-8">
                    <div class="mermaid">
                        graph TD
                            A[多线程编程] --> B[高并发请求处理]
                            A --> C[并行数据处理]
                            A --> D[任务调度]
                            A --> E[并发控制]
                            A --> F[后台任务]
                            A --> G[实时数据处理]
                            
                            B --> B1[线程池管理]
                            B --> B2[异步处理]
                            
                            C --> C1[Fork/Join框架]
                            C --> C2[Stream API]
                            
                            D --> D1[定时任务]
                            D --> D2[调度器]
                            
                            E --> E1[锁机制]
                            E --> E2[原子操作]
                            
                            F --> F1[CompletableFuture]
                            F --> F2[消息队列]
                            
                            G --> G1[流处理框架]
                            G --> G2[实时分析]
                            
                            style A fill:#667eea,stroke:#fff,stroke-width:3px,color:#fff
                            style B fill:#f59e0b,stroke:#fff,stroke-width:2px,color:#fff
                            style C fill:#10b981,stroke:#fff,stroke-width:2px,color:#fff
                            style D fill:#3b82f6,stroke:#fff,stroke-width:2px,color:#fff
                            style E fill:#ef4444,stroke:#fff,stroke-width:2px,color:#fff
                            style F fill:#8b5cf6,stroke:#fff,stroke-width:2px,color:#fff
                            style G fill:#ec4899,stroke:#fff,stroke-width:2px,color:#fff
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <section class="py-16 bg-white">
        <div class="container mx-auto px-6">
            <div class="max-w-6xl mx-auto">
                
                <!-- 1. 高并发请求处理 -->
                <div class="mb-16">
                    <div class="flex items-center mb-6">
                        <span class="section-number">1</span>
                        <h2 class="text-3xl font-bold text-gray-800">高并发请求处理</h2>
                    </div>
                    
                    <div class="bg-gradient-to-r from-orange-50 to-yellow-50 rounded-lg p-8 mb-8 card-hover">
                        <div class="flex items-start mb-4">
                            <i class="fas fa-server text-3xl text-orange-500 mr-4 mt-1"></i>
                            <div>
                                <h3 class="text-xl font-semibold mb-2 text-gray-800">应用场景</h3>
                                <p class="text-gray-700">在Web服务器中，处理大量并发的HTTP请求时，多线程可以显著提升系统的吞吐量和响应速度。</p>
                            </div>
                        </div>
                    </div>

                    <div class="grid md:grid-cols-2 gap-6 mb-8">
                        <div class="bg-white rounded-lg shadow-md p-6 card-hover">
                            <h4 class="text-lg font-semibold mb-3 flex items-center">
                                <i class="fas fa-layer-group text-orange-500 mr-2"></i>
                                线程池
                            </h4>
                            <p class="text-gray-600">使用线程池来管理请求处理线程，避免每次请求都创建和销毁线程的开销。例如，使用Java的ExecutorService来管理线程池。</p>
                        </div>
                        <div class="bg-white rounded-lg shadow-md p-6 card-hover">
                            <h4 class="text-lg font-semibold mb-3 flex items-center">
                                <i class="fas fa-sync-alt text-orange-500 mr-2"></i>
                                异步处理
                            </h4>
                            <p class="text-gray-600">将耗时的任务（如数据库操作、外部API调用）异步处理，避免阻塞主线程，提高响应速度。</p>
                        </div>
                    </div>

                    <div class="code-block">
                        <pre><code>// 创建线程池
ExecutorService executor = Executors.newFixedThreadPool(10);

// 提交任务
executor.submit(() -> {
    // 处理请求的逻辑
});</code></pre>
                    </div>
                </div>

                <!-- 2. 并行数据处理 -->
                <div class="mb-16">
                    <div class="flex items-center mb-6">
                        <span class="section-number">2</span>
                        <h2 class="text-3xl font-bold text-gray-800">并行数据处理</h2>
                    </div>
                    
                    <div class="bg-gradient-to-r from-green-50 to-emerald-50 rounded-lg p-8 mb-8 card-hover">
                        <div class="flex items-start mb-4">
                            <i class="fas fa-database text-3xl text-green-500 mr-4 mt-1"></i>
                            <div>
                                <h3 class="text-xl font-semibold mb-2 text-gray-800">应用场景</h3>
                                <p class="text-gray-700">在处理大数据集时，多线程可以加速数据处理和计算过程。例如，在数据分析或报表生成过程中。</p>
                            </div>
                        </div>
                    </div>

                    <div class="grid md:grid-cols-2 gap-6 mb-8">
                        <div class="bg-white rounded-lg shadow-md p-6 card-hover">
                            <h4 class="text-lg font-semibold mb-3 flex items-center">
                                <i class="fas fa-code-branch text-green-500 mr-2"></i>
                                Fork/Join框架
                            </h4>
                            <p class="text-gray-600">使用Java的Fork/Join框架将大任务拆分为小任务并行处理，以提高计算效率。</p>
                        </div>
                        <div class="bg-white rounded-lg shadow-md p-6 card-hover">
                            <h4 class="text-lg font-semibold mb-3 flex items-center">
                                <i class="fas fa-stream text-green-500 mr-2"></i>
                                Stream API
                            </h4>
                            <p class="text-gray-600">使用Java 8的Stream API进行并行流处理，可以简化并行数据处理的实现。</p>
                        </div>
                    </div>

                    <div class="code-block">
                        <pre><code>// 使用Fork/Join框架
ForkJoinPool pool = new ForkJoinPool();
pool.invoke(new RecursiveTask<Void>() {
    @Override
    protected Void compute() {
        // 分治法处理任务
        return null;
    }
});

// 使用Stream API并行处理
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
numbers.parallelStream().forEach(n -> {
    // 处理数据
});</code></pre>
                    </div>
                </div>

                <!-- 3. 任务调度与定时任务 -->
                <div class="mb-16">
                    <div class="flex items-center mb-6">
                        <span class="section-number">3</span>
                        <h2 class="text-3xl font-bold text-gray-800">任务调度与定时任务</h2>
                    </div>
                    
                    <div class="bg-gradient-to-r from-blue-50 to-indigo-50 rounded-lg p-8 mb-8 card-hover">
                        <div class="flex items-start mb-4">
                            <i class="fas fa-clock text-3xl text-blue-500 mr-4 mt-1"></i>
                            <div>
                                <h3 class="text-xl font-semibold mb-2 text-gray-800">应用场景</h3>
                                <p class="text-gray-700">定期执行某些任务，例如定时备份、数据清理或发送定期报告。</p>
                            </div>
                        </div>
                    </div>

                    <div class="grid md:grid-cols-2 gap-6 mb-8">
                        <div class="bg-white rounded-lg shadow-md p-6 card-hover">
                            <h4 class="text-lg font-semibold mb-3 flex items-center">
                                <i class="fas fa-calendar-alt text-blue-500 mr-2"></i>
                                ScheduledExecutorService
                            </h4>
                            <p class="text-gray-600">使用ScheduledExecutorService来安排和执行定时任务。</p>
                        </div>
                        <div class="bg-white rounded-lg shadow-md p-6 card-hover">
                            <h4 class="text-lg font-